<script>
	import { ethers } from "ethers";
	export default {
		onLaunch: async () => {
			console.log('App Launch')
			// 设置用户转成币安链
			if (window.ethereum) {
				window.ethereum.request({
					method: 'wallet_switchEthereumChain',
					params: [{
						chainId: ethers.utils.hexlify(8453) //链id
					}]
				}).then(() => {
					// console.log('ETH')
				})
				.catch((e) => {
					console.log('chainId error')
				})
			}
			if (window.ethereum) {
				// 监听用户地址变化和断开链接
				ethereum.on('accountsChanged', (accounts) => {
					console.log('监听用户地址变化和断开链接',accounts);
					// this.logout()
				});
				ethereum.on('chainChanged', (accounts) => {
					console.log('用户切换网络',accounts);
					// this.logout()
				});
			} else {
				console.log('metamask!')
			}
		},
		onShow: function() {
			console.log('App Show')

		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	page {
		background-color: #ffffff;
	}
</style>
<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-plus/index.scss";

	// 公共背景
	.pagebg {
		width: 100vw;
		min-height: 100vh;
		background: linear-gradient(to right bottom, #1890FF20, #1890FF01);
		color: #333333;
		font-size: 28rpx;
	}

	.bottom-box {
		height: calc(120rpx + env(safe-area-inset-bottom) + 40rpx);
	}
</style>